package javaEight;

import org.junit.Test;

import java.util.Comparator;

/**
 * @description:Lambda的使用
 * @author:Mr.Cat
 * @create:2021-12-06 21:55
 **/
public class LambdaTest {
    @Test
    public void test1(){
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱我的宝儿");
            }
        };
        r1.run();

        System.out.println("---------------------");
//Lambda的使用
        Runnable r2 = () -> System.out.println("我喜欢皮皮");

        r2.run();
    }
    @Test
    public void test2(){
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1,Integer o2) {
                return Integer.compare(o1,o2);
            }
        };

        int compare1 = com1.compare(11,13);
        System.out.println(compare1);

        System.out.println("--------------");
        //Lambda的写法
        Comparator<Integer> com2 = (o1,o2) -> Integer.compare(o1,o2);
        int compare2 = com2.compare(13,10);
        System.out.println(compare2);

        System.out.println("--------------");

        //方法引用的写法
        Comparator<Integer> com3 = Integer :: compare;
        int compare3 = com2.compare(10,10);
        System.out.println(compare3);
    }
}

